/*
 * MLscheduler.h
 *
 *  Created on: Jun 28, 2009
 *      Author: yanir
 */

#ifndef MLSCHEDULER_H_
#define MLSCHEDULER_H_

#include "OSScheduler.h"
#include "RRscheduler.h"
#include "Mailer.h"
#include <queue>


class MLscheduler : public OSScheduler
{
	//typedef map<string,TT> threadsTable ;

	private:

//	queue<Worker*> m_blocked_threads; /* a queue of blocked threads */

//	queue<Worker*> m_active_threads;  /* a queue of active threads */

	Mailer* m_mailer;

	map<string, Worker>* m_workers;

	int m_quanta; /* message quanta qiven to the scheduler to work with */

	int m_contex_switch_count;

	int m_quanta_count;    /* total quanta given */

	int m_msg_passed_count;

	int m_phase_count;

	//threadsTable*  m_tT;


	//// Additional info for the multilevel scheduler ///

	vector<RRscheduler*> m_p_queues; /* queues by priority - holds 4 round robin queues (0-3  , 0 -the lowest) */

	int m_current_queue;  /*  the current queue we are working on */

	int m_users_in_queue; /*  the number of users in the  round robin queue */

	bool m_switch_queue;  /* indicator to switch the work to other queue in line */





	public:

	/* C'tor  */
	MLscheduler();

	MLscheduler(int quanta,map<string, Worker>* workers ,Mailer* mailer);

	/* D'tor - destroys the SampleThread */
	virtual ~MLscheduler();


	/* init scheduler*/
	void init();

	/*next worker*/

	void nextWorker();
	//void* getThreadsTable();

	int getQuanta();

	//map<string, Worker>* getWorkers();

	/* increment the contex switches count by 1 */
	void incCScount();

	/* increment the quanta given count by 1 */
	void incQuantaCount();

	/* increment the message passed count by 1 */
	void incMsgPass();

	bool isStable();

	void printSum();


	// Additional functions for the multilevel scheduler //

	/* switch work to next queue in line */
	void switchQueue(RRscheduler* current_queue);

	/* move workers to other queues based on their priority */
	void changePriorities(RRscheduler* current_queue);

	vector<Worker*> getQueueUsers(RRscheduler* current_queue);



};
#endif /* MLSCHEDULER_H_ */

